package com.hgb.mall.mbg.mapper;

import com.hgb.mall.mbg.entity.OmsCartItem;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

import javax.annotation.Generated;
import java.util.List;
import java.util.Optional;

import static com.hgb.mall.mbg.mapper.OmsCartItemDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;

@Mapper
public interface OmsCartItemMapper {
    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    BasicColumn[] selectList = BasicColumn
            .columnList(id, productId, productSkuId, memberId, quantity, price, productPic, productName, productBrand, productSn, productSubTitle, productSkuCode, memberNickname, createDate, modifyDate, deleteStatus, productCategoryId, productAttr);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    static UpdateDSL<UpdateModel> updateAllColumns(OmsCartItem record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(productId).equalTo(record::getProductId)
                  .set(productSkuId).equalTo(record::getProductSkuId)
                  .set(memberId).equalTo(record::getMemberId)
                  .set(quantity).equalTo(record::getQuantity)
                  .set(price).equalTo(record::getPrice)
                  .set(productPic).equalTo(record::getProductPic)
                  .set(productName).equalTo(record::getProductName)
                  .set(productBrand).equalTo(record::getProductBrand)
                  .set(productSn).equalTo(record::getProductSn)
                  .set(productSubTitle).equalTo(record::getProductSubTitle)
                  .set(productSkuCode).equalTo(record::getProductSkuCode)
                  .set(memberNickname).equalTo(record::getMemberNickname)
                  .set(createDate).equalTo(record::getCreateDate)
                  .set(modifyDate).equalTo(record::getModifyDate)
                  .set(deleteStatus).equalTo(record::getDeleteStatus)
                  .set(productCategoryId).equalTo(record::getProductCategoryId)
                  .set(productAttr).equalTo(record::getProductAttr);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(OmsCartItem record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(productId).equalToWhenPresent(record::getProductId)
                  .set(productSkuId).equalToWhenPresent(record::getProductSkuId)
                  .set(memberId).equalToWhenPresent(record::getMemberId)
                  .set(quantity).equalToWhenPresent(record::getQuantity)
                  .set(price).equalToWhenPresent(record::getPrice)
                  .set(productPic).equalToWhenPresent(record::getProductPic)
                  .set(productName).equalToWhenPresent(record::getProductName)
                  .set(productBrand).equalToWhenPresent(record::getProductBrand)
                  .set(productSn).equalToWhenPresent(record::getProductSn)
                  .set(productSubTitle).equalToWhenPresent(record::getProductSubTitle)
                  .set(productSkuCode).equalToWhenPresent(record::getProductSkuCode)
                  .set(memberNickname).equalToWhenPresent(record::getMemberNickname)
                  .set(createDate).equalToWhenPresent(record::getCreateDate)
                  .set(modifyDate).equalToWhenPresent(record::getModifyDate)
                  .set(deleteStatus).equalToWhenPresent(record::getDeleteStatus)
                  .set(productCategoryId).equalToWhenPresent(record::getProductCategoryId)
                  .set(productAttr).equalToWhenPresent(record::getProductAttr);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    long count(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @DeleteProvider(type = SqlProviderAdapter.class, method = "delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @InsertProvider(type = SqlProviderAdapter.class, method = "insert")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "record.id", before = false, resultType = Long.class)
    int insert(InsertStatementProvider<OmsCartItem> insertStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    @ResultMap("OmsCartItemResult")
    Optional<OmsCartItem> selectOne(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    @Results(id = "OmsCartItemResult", value = {
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "product_id", property = "productId", jdbcType = JdbcType.BIGINT),
            @Result(column = "product_sku_id", property = "productSkuId", jdbcType = JdbcType.BIGINT),
            @Result(column = "member_id", property = "memberId", jdbcType = JdbcType.BIGINT),
            @Result(column = "quantity", property = "quantity", jdbcType = JdbcType.INTEGER),
            @Result(column = "price", property = "price", jdbcType = JdbcType.DECIMAL),
            @Result(column = "product_pic", property = "productPic", jdbcType = JdbcType.VARCHAR),
            @Result(column = "product_name", property = "productName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "product_brand", property = "productBrand", jdbcType = JdbcType.VARCHAR),
            @Result(column = "product_sn", property = "productSn", jdbcType = JdbcType.VARCHAR),
            @Result(column = "product_sub_title", property = "productSubTitle", jdbcType = JdbcType.VARCHAR),
            @Result(column = "product_sku_code", property = "productSkuCode", jdbcType = JdbcType.VARCHAR),
            @Result(column = "member_nickname", property = "memberNickname", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_date", property = "createDate", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "modify_date", property = "modifyDate", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "delete_status", property = "deleteStatus", jdbcType = JdbcType.INTEGER),
            @Result(column = "product_category_id", property = "productCategoryId", jdbcType = JdbcType.BIGINT),
            @Result(column = "product_attr", property = "productAttr", jdbcType = JdbcType.VARCHAR)
    })
    List<OmsCartItem> selectMany(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @UpdateProvider(type = SqlProviderAdapter.class, method = "update")
    int update(UpdateStatementProvider updateStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, omsCartItem, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, omsCartItem, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int deleteByPrimaryKey(Long id_) {
        return delete(c ->
                c.where(id, isEqualTo(id_))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insert(OmsCartItem record) {
        return MyBatis3Utils.insert(this::insert, record, omsCartItem, c ->
                c.map(productId).toProperty("productId")
                 .map(productSkuId).toProperty("productSkuId")
                 .map(memberId).toProperty("memberId")
                 .map(quantity).toProperty("quantity")
                 .map(price).toProperty("price")
                 .map(productPic).toProperty("productPic")
                 .map(productName).toProperty("productName")
                 .map(productBrand).toProperty("productBrand")
                 .map(productSn).toProperty("productSn")
                 .map(productSubTitle).toProperty("productSubTitle")
                 .map(productSkuCode).toProperty("productSkuCode")
                 .map(memberNickname).toProperty("memberNickname")
                 .map(createDate).toProperty("createDate")
                 .map(modifyDate).toProperty("modifyDate")
                 .map(deleteStatus).toProperty("deleteStatus")
                 .map(productCategoryId).toProperty("productCategoryId")
                 .map(productAttr).toProperty("productAttr")
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insertSelective(OmsCartItem record) {
        return MyBatis3Utils.insert(this::insert, record, omsCartItem, c ->
                c.map(productId).toPropertyWhenPresent("productId", record::getProductId)
                 .map(productSkuId).toPropertyWhenPresent("productSkuId", record::getProductSkuId)
                 .map(memberId).toPropertyWhenPresent("memberId", record::getMemberId)
                 .map(quantity).toPropertyWhenPresent("quantity", record::getQuantity)
                 .map(price).toPropertyWhenPresent("price", record::getPrice)
                 .map(productPic).toPropertyWhenPresent("productPic", record::getProductPic)
                 .map(productName).toPropertyWhenPresent("productName", record::getProductName)
                 .map(productBrand).toPropertyWhenPresent("productBrand", record::getProductBrand)
                 .map(productSn).toPropertyWhenPresent("productSn", record::getProductSn)
                 .map(productSubTitle).toPropertyWhenPresent("productSubTitle", record::getProductSubTitle)
                 .map(productSkuCode).toPropertyWhenPresent("productSkuCode", record::getProductSkuCode)
                 .map(memberNickname).toPropertyWhenPresent("memberNickname", record::getMemberNickname)
                 .map(createDate).toPropertyWhenPresent("createDate", record::getCreateDate)
                 .map(modifyDate).toPropertyWhenPresent("modifyDate", record::getModifyDate)
                 .map(deleteStatus).toPropertyWhenPresent("deleteStatus", record::getDeleteStatus)
                 .map(productCategoryId).toPropertyWhenPresent("productCategoryId", record::getProductCategoryId)
                 .map(productAttr).toPropertyWhenPresent("productAttr", record::getProductAttr)
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default Optional<OmsCartItem> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, omsCartItem, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default List<OmsCartItem> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, omsCartItem, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default List<OmsCartItem> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, omsCartItem, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default Optional<OmsCartItem> selectByPrimaryKey(Long id_) {
        return selectOne(c ->
                c.where(id, isEqualTo(id_))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, omsCartItem, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKey(OmsCartItem record) {
        return update(c ->
                c.set(productId).equalTo(record::getProductId)
                 .set(productSkuId).equalTo(record::getProductSkuId)
                 .set(memberId).equalTo(record::getMemberId)
                 .set(quantity).equalTo(record::getQuantity)
                 .set(price).equalTo(record::getPrice)
                 .set(productPic).equalTo(record::getProductPic)
                 .set(productName).equalTo(record::getProductName)
                 .set(productBrand).equalTo(record::getProductBrand)
                 .set(productSn).equalTo(record::getProductSn)
                 .set(productSubTitle).equalTo(record::getProductSubTitle)
                 .set(productSkuCode).equalTo(record::getProductSkuCode)
                 .set(memberNickname).equalTo(record::getMemberNickname)
                 .set(createDate).equalTo(record::getCreateDate)
                 .set(modifyDate).equalTo(record::getModifyDate)
                 .set(deleteStatus).equalTo(record::getDeleteStatus)
                 .set(productCategoryId).equalTo(record::getProductCategoryId)
                 .set(productAttr).equalTo(record::getProductAttr)
                 .where(id, isEqualTo(record::getId))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKeySelective(OmsCartItem record) {
        return update(c ->
                c.set(productId).equalToWhenPresent(record::getProductId)
                 .set(productSkuId).equalToWhenPresent(record::getProductSkuId)
                 .set(memberId).equalToWhenPresent(record::getMemberId)
                 .set(quantity).equalToWhenPresent(record::getQuantity)
                 .set(price).equalToWhenPresent(record::getPrice)
                 .set(productPic).equalToWhenPresent(record::getProductPic)
                 .set(productName).equalToWhenPresent(record::getProductName)
                 .set(productBrand).equalToWhenPresent(record::getProductBrand)
                 .set(productSn).equalToWhenPresent(record::getProductSn)
                 .set(productSubTitle).equalToWhenPresent(record::getProductSubTitle)
                 .set(productSkuCode).equalToWhenPresent(record::getProductSkuCode)
                 .set(memberNickname).equalToWhenPresent(record::getMemberNickname)
                 .set(createDate).equalToWhenPresent(record::getCreateDate)
                 .set(modifyDate).equalToWhenPresent(record::getModifyDate)
                 .set(deleteStatus).equalToWhenPresent(record::getDeleteStatus)
                 .set(productCategoryId).equalToWhenPresent(record::getProductCategoryId)
                 .set(productAttr).equalToWhenPresent(record::getProductAttr)
                 .where(id, isEqualTo(record::getId))
        );
    }
}
